import { configureStore, combineReducers } from '@reduxjs/toolkit'
import { persistStore, persistReducer } from 'redux-persist'
import storage from 'redux-persist/lib/storage'


import globalSlice from './global.store'
import bookSlice from './book.store'

const rootReducer = combineReducers({
  global: globalSlice,
  book: bookSlice
})


const persistConfig = {
  key: 'root',
  storage,
  whitelist: ['global']
}

const persistedReducer = persistReducer(persistConfig, rootReducer)

export const store = configureStore({
  reducer: persistedReducer,
  middleware: (getDefaultMiddleware) =>
    getDefaultMiddleware({
      serializableCheck: false
    })
})

export const persistor = persistStore(store)
